//
//  HomeDetailBuyView.m
//  share_business
//
//  Created by 吴于凌 on 2017/9/10.
//  Copyright © 2017年 wyl. All rights reserved.
//

#import "HomeDetailBuyView.h"
#import "BSCommon.h"
#import "SearchViewItemView.h"
const static int view_height = 520 ;
@interface HomeDetailBuyView()<UITextFieldDelegate>

@property(nonatomic,strong)UIScrollView *scrollView ;
@property(nonatomic,strong)UILabel *titleLabel ;
@property(nonatomic,strong)UILabel *newestLabel ;
@property(nonatomic,strong)UILabel *oldLabel ;


@property(nonatomic,strong)UILabel *codeLabel ;//
@property(nonatomic,strong)UILabel *zekouLabel ;//
@property(nonatomic,strong)UILabel *shareValueLabel ;//


/**添加按钮*/
@property (nonatomic,strong) UIButton *addBtn;
/**减少按钮*/
@property (nonatomic,strong) UIButton *reduceBtn;
/**数量*/
@property (nonatomic,strong) UITextField *numbersTf;

@end

@implementation HomeDetailBuyView
-(instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        UIColor *color = [UIColor blackColor];
        self.backgroundColor =[color colorWithAlphaComponent:0.3];
 
        [self initView];
    }
    return self;
}

-(void)initView{
    UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, APPHEIGHT - view_height, APPWIDTH, view_height)];
    bgView.backgroundColor = [UIColor whiteColor];
    UIView *part1View = [[UIView alloc]init];//商品详情部分
    [bgView addSubview:part1View];
    [self addSubview:bgView];
    
    //***********************************part1*****************************************//
    UIImageView *imageView = [BSWidget commonImageViewWithFrame:CGRectZero image:ImageNamed(nil)];
    UIView *rightView = [[UIView alloc]initWithFrame:CGRectZero];
    _titleLabel = [BSWidget commonLableWithFrame:CGRectZero text:@"法国进口红酒" color:nil font:16];
    _newestLabel=[BSWidget commonLableWithFrame:CGRectZero text:@"¥499" color:nil font:15];
    _oldLabel = [BSWidget commonLableWithFrame:CGRectZero text:@"价格¥699" color:nil font:13];
    _codeLabel = [BSWidget commonLableWithFrame:CGRectZero text:@"商品编号:111111" color:nil font:12];
    _zekouLabel = [BSWidget commonLableWithFrame:CGRectZero text:@"等级折扣:20:00" color:nil font:12];
    _shareValueLabel = [BSWidget commonLableWithFrame:CGRectZero text:@"预分享值:520" color:nil font:12];
    UIButton *closeBtn = [BSWidget commonButtonWithFrame:CGRectZero title:nil color:nil fontSize:0 target:self action:@selector(closeDialog)];
    [closeBtn setImage:ImageNamed(@"close") forState:UIControlStateNormal];
    
    [rightView addSubview:_titleLabel];
    [rightView addSubview:_newestLabel];
    [rightView addSubview:_oldLabel];
    [rightView addSubview:_codeLabel];
    [rightView addSubview:_zekouLabel];
    [rightView addSubview:_shareValueLabel];
    [rightView addSubview:closeBtn];
    [part1View addSubview:imageView];
    [part1View addSubview:rightView];
    
    part1View.frame = CGRectMake(0, 0, APPWIDTH, 145);
    imageView.frame = CGRectMake(15,- 30, 130, 130); 
    [imageView setBorder:1 cornerRadius:10 color:[UIColor colorWithHexString:@"dddddd"]];
    imageView.layer.masksToBounds =YES ;
    rightView.frame = CGRectMake(imageView.maxX, 0, APPWIDTH - imageView.width, 90);

    _titleLabel.frame = CGRectMake(10, 0, 200, 30) ;
    _newestLabel.frame = CGRectMake(10, _titleLabel.maxY, 60, 30);
    _newestLabel.textColor = [UIColor orangeColor];
    _oldLabel.frame = CGRectMake(_newestLabel.maxX, _newestLabel.y, 100, 30);
    
    _codeLabel.frame = CGRectMake(10, _oldLabel.maxY, 200, 20);
    _codeLabel.textColor = RGBA(102, 102, 102, 1) ;
    
    _zekouLabel.frame = CGRectMake(10, _codeLabel.maxY+3, 200, 20);
    _zekouLabel.textColor = RGBA(102, 102, 102, 1) ;
    
    _shareValueLabel.frame = CGRectMake(10, _zekouLabel.maxY +3, 200, 20);
    _shareValueLabel.textColor = RGBA(102, 102, 102, 1) ;
    closeBtn.frame = CGRectMake(rightView.width - 60, 0, 35, 35);
    //*************************************part2*******************************************//
    self.scrollView = [[UIScrollView alloc]init];
    [bgView addSubview:self.scrollView];
    self.scrollView.frame = CGRectMake(0, part1View.maxY, APPWIDTH, view_height - part1View.height);
    UIView *part2View = [[UIView alloc]init];
    [self.scrollView addSubview:part2View];
    
    part2View.frame = CGRectMake(0, 0, APPWIDTH, 120);
    NSArray *array = @[@"属性1",@"属性1",@"属性1",@"属性1",@"属性1",@"属性1",@"属性1"];
    UILabel * fenlei1 = [BSWidget commonLableWithFrame:CGRectZero text:@"分类一" color:[UIColor blackColor] font:15];
    fenlei1.frame = CGRectMake(10, 0, APPWIDTH, 30);

    
    SearchViewItemView *view = [[SearchViewItemView alloc]init];
    UIView *dateView = [view creatBtn:array];
    dateView.height = view.showMaxY;
    dateView.y = fenlei1.maxY ;
    
    [part2View addSubview:dateView];
    [part2View addSubview:fenlei1];
    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(20, part2View.maxY -10, APPWIDTH -40, 1)];
    [part2View addSubview:line1];
    line1.backgroundColor = [UIColor colorWithHexString:@"#dddddd"];
    //*************************************part2******************************************//
    
    UIView *part3View = [[UIView alloc]init];
    [self.scrollView addSubview:part3View];
    part3View.frame = CGRectMake(0, part2View.maxY, APPWIDTH, 120);
    NSArray *array2 = @[@"属性1",@"属性1",@"属性1",@"属性1",@"属性1",@"属性1",@"属性1"];
    UILabel * fenlei2 = [BSWidget commonLableWithFrame:CGRectZero text:@"分类二" color:[UIColor blackColor] font:15];
    fenlei2.frame = CGRectMake(10, 0, APPWIDTH, 30);
    
    SearchViewItemView *itemView2 = [[SearchViewItemView alloc]init];
    UIView *dataView2 = [itemView2 creatBtn:array2];
    dataView2.height = itemView2.showMaxY;
    dataView2.y = fenlei2.maxY ;
    
    [part3View addSubview:dataView2];
    [part3View addSubview:fenlei2];
    
//    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(20, part3View.maxY - 10, APPWIDTH -40, 1)];
//    [part3View addSubview:line2];
//    line2.backgroundColor = [UIColor colorWithHexString:@"#dddddd"];
    
     //*************************************part3******************************************//
    UIView *part4View = [[UIView alloc]init];
    [self.scrollView addSubview:part4View];
    part4View.frame = CGRectMake(0, part3View.maxY, APPWIDTH, 120);
    UILabel * fenlei3 = [BSWidget commonLableWithFrame:CGRectZero text:@"购买数量" color:[UIColor blackColor] font:15];
    fenlei3.frame = CGRectMake(10, 0, APPWIDTH, 30);
       [part4View addSubview:fenlei3];
    //加 按钮
    _addBtn = [[UIButton alloc]init];
    [_addBtn setImage:ImageNamed(@"add") forState:UIControlStateNormal];
    _addBtn.tag = 1;
//    [_addBtn addTarget:self action:@selector(goodsCountNumClick:) forControlEvents:UIControlEventTouchUpInside];
    [_addBtn setBorder:1 cornerRadius:0];
    [part4View addSubview:_addBtn];
    
    //减 按钮
    _reduceBtn = [[UIButton alloc]init];
    [_reduceBtn setImage:ImageNamed(@"reduce") forState:UIControlStateNormal];
    _reduceBtn.tag = 2;
    [_reduceBtn setBorder:1 cornerRadius:0];
//    [_reduceBtn addTarget:self action:@selector(goodsCountNumClick:) forControlEvents:UIControlEventTouchUpInside];
    [part4View addSubview:_reduceBtn];
    //数量
    _numbersTf = [[UITextField alloc]init];
    _numbersTf.textAlignment = NSTextAlignmentCenter;
    _numbersTf.keyboardType = UIKeyboardTypeNumberPad;
    _numbersTf.delegate = self ;
    [_numbersTf setBorder:1 cornerRadius:0];
    _numbersTf.font =[UIFont systemFontOfSize:13];
    _numbersTf .background = ImageNamed(@"shopping_cell_textfield_bj_53x39_");
//    [_numbersTf addTarget:self action:@selector(textFieldDidChange:) forControlEvents:UIControlEventEditingChanged];
    [part4View addSubview:_numbersTf];
    
//    UIView *line3 = [[UIView alloc]initWithFrame:CGRectMake(20, part4View.maxY-10, APPWIDTH -40, 1)];
//    [part4View addSubview:line3];
//    line3.backgroundColor = [UIColor colorWithHexString:@"#dddddd"];
//    
    
    CGFloat btnW = 30;
    _reduceBtn.frame = CGRectMake(APPWIDTH - 160, 0, btnW, btnW);
    _numbersTf.frame = CGRectMake(CGRectGetMaxX(_reduceBtn.frame)-1.5, 0, btnW+20, btnW);
    _addBtn.frame = CGRectMake(CGRectGetMaxX(_numbersTf.frame)-1.5,0, btnW, btnW);
    
    self.scrollView.contentSize= CGSizeMake(APPWIDTH, part4View.maxY+15);
    UIButton *sureButton = [BSWidget commonButtonWithFrame:CGRectMake(0, view_height - 55, APPWIDTH, 55) title:@"确认" color:nil fontSize:15 target:self action:@selector(sureBuy)];
    sureButton.backgroundColor =[UIColor orangeColor];
    [bgView addSubview:sureButton];
}
-(void)closeDialog{
    [self.subviews makeObjectsPerformSelector:@selector(removeFromSuperview)];
    [self removeFromSuperview];
}
-(void)sureBuy{

    if (self.delegate) {
       [self.delegate WriteOrder];
    }

    
}
@end
